﻿var regexEnum = 
{
	intege:"^-?[1-9]\\d*$",					//鏁存暟
	intege1:"^[1-9]\\d*$",					//姝ｆ暣鏁?
	intege2:"^-[1-9]\\d*$",					//璐熸暣鏁?
	num:"^([+-]?)\\d*\\.?\\d+$",				//鏁板瓧
	num1:"^([+]?)\\d*\\.?\\d+$",				//姝ｆ暟
	num2:"^-\\d*\\.?\\d+$",					//璐熸暟
	decmal:"^([+-]?)\\d*\\.\\d+$",				//娴偣鏁?
	decmal1:"^([+]?)\\d*\\.\\d+$",				//姝ｆ诞镣规暟
	decmal2:"^-\\d*\\.\\d+$",				//璐熸诞镣规暟
	email:"^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$", //闾欢
	emailgroup:"^(\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+,)*\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$", //闾欢缇?
	color:"^[a-fA-F0-9]{6}$",				//棰滆壊
	url:"^http[s]?:\\/\\/([\\w-]+\\.)+[\\w-]+([\\w-./?%&=]*)?$",	//url
	chinese:"^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$",		//浠呬腑鏂?
	ascii:"^[\\x00-\\xFF]+$",				//浠匒CSII瀛楃
	zipcode:"^\\d{6}$",					//闾紪
	mobile:"^(13|15)[0-9]{9}$",				//镓嬫満
	ip4:"^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5]).(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5]).(d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5]).(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$",				//ip鍦板潃
	notempty:"^\\S+$",					//闱炵┖
	picture:"(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$",	//锲剧墖
	rar:"(.*)\\.(rar|zip|7zip|tgz)$",			//铡嬬缉鏂囦欢
	date:"^\\d{4}(\\-|\\/|\.)\\d{1,2}\\1\\d{1,2}$",		//镞ユ湡
	qq:"^[1-9]*[1-9][0-9]*$",				//QQ鍙风爜
	tel:"(\\d{3}-|\\d{4}-)?(\\d{8}|\\d{7})",		//锲藉唴鐢佃瘽
	username:"^[A-Za-z\\u4E00-\\u9FA5\\uF900-\\uFA2D]+[A-Za-z0-9\\u4E00-\\u9FA5\\uF900-\\uFA2D\\-\\_]*$",					//鍙互鏄腑鏂囥€佽嫳鏂囥€佹暟瀛椼€?銆乢
	letter:"^[A-Za-z]+$",					//瀛楁瘝
	letter_u:"^[A-Z]+$",					//澶у啓瀛楁瘝
	letter_l:"^[a-z]+$",					//灏忓啓瀛楁瘝
	idcard:"^[1-9]([0-9]{14}|[0-9]{17})$"	//韬唤璇?
}

var aCity={11:"鍖椾含",12:"澶╂触",13:"娌冲寳",14:"灞辫タ",15:"鍐呰挋鍙?,21:"杈藉畞",22:"鍚夋滠",23:"榛戦緳姹?,31:"涓婃捣",32:"姹熻嫃",33:"娴欐睙",34:"瀹夊窘",35:"绂忓缓",36:"姹熻タ",37:"灞变笢",41:"娌冲崡",42:"婀栧寳",43:"婀栧崡",44:"骞夸笢",45:"骞胯タ",46:"娴峰崡",50:"閲嶅简",51:"锲涘窛",52:"璐靛窞",53:"浜戝崡",54:"瑗胯棌",61:"闄曡タ",62:"鐢樿们",63:"闱掓捣",64:"瀹佸",65:"鏂扮枂",71:"鍙版咕",81:"棣欐腐",82:"婢抽棬",91:"锲藉"} 

function isCardID(sId){ 
	var iSum=0 ;
	var info="" ;
	if(!/^\d{17}(\d|x)$/i.test(sId)) return "浣犺緭鍏ョ殑韬唤璇侀昵搴︽垨镙煎纺阌栾"; 
	sId=sId.replace(/x$/i,"a"); 
	if(aCity[parseInt(sId.substr(0,2))]==null) return "浣犵殑韬唤璇佸湴鍖洪潪娉?; 
	sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2)); 
	var d=new Date(sBirthday.replace(/-/g,"/")) ;
	if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return "韬唤璇佷笂镄勫嚭鐢熸棩链熼潪娉?; 
	for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11) ;
	if(iSum%11!=1) return "浣犺緭鍏ョ殑韬唤璇佸佛闱炴硶"; 
	return true;//aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"鐢?:"濂?) 
} 


var jQuery_formValidator_initConfig;
(function($) {

$.formValidator = 
{
	//鍚勭镙￠獙鏂瑰纺鏀寔镄勬带浠剁被鍨?
	sustainType : function(id,setting)
	{
		var elem = $("#"+id).get(0);
		var srcTag = elem.tagName;
		var stype = elem.type;
		switch(setting.validateType)
		{
			case "InitValidator":
				return true;
			case "InputValidator":
				if (srcTag == "INPUT" || srcTag == "TEXTAREA" || srcTag == "SELECT"){
					return true;
				}else{
					return false;
				}
			case "CompareValidator":
				if (srcTag == "INPUT" || srcTag == "TEXTAREA")
				{
					if (stype == "checkbox" || stype == "radio"){
						return false;
					}else{
						return true;
					}
				}
				return false;
			case "AjaxValidator":
				if (stype == "text" || stype == "textarea" || stype == "file" || stype == "select-one"){
					return true;
				}else{
					return false;
				}
			case "RegexValidator":
				if (srcTag == "INPUT" || srcTag == "TEXTAREA")
				{
					if (stype == "checkbox" || stype == "radio"){
						return false;
					}else{
						return true;
					}
				}
				return false;
			case "FunctionValidator":
			    return true;
		}
	},
    
	initConfig : function(controlOptions)
	{
		var settings = 
		{
			validatorGroup : "1",
			alertMessage:false,
			onSuccess: function() {return true;},
			onError:function() {},
			submitOnce:false
		};
		controlOptions = controlOptions || {};
		$.extend(settings, controlOptions);
		if (jQuery_formValidator_initConfig == null ){jQuery_formValidator_initConfig = new Array();}
		jQuery_formValidator_initConfig.push( settings );
	},
	
	//濡傛灉validator瀵硅薄瀵瑰簲镄别lement瀵硅薄镄剉alidator灞炴€ц拷锷犺杩涜镄勬牎楠屻€?
	appendValid : function(id, setting )
	{
		//濡傛灉鏄悇绉嶆牎楠屼笉鏀寔镄勭被鍨嬶紝灏变笉杩藉姞鍒般€傝繑锲?1琛ㄧず娌℃湁杩藉姞鎴愬姛
		if(!$.formValidator.sustainType(id,setting)) return -1;
		var srcjo = $("#"+id).get(0);   
		if (setting.validateType=="InitValidator" || !srcjo.settings || srcjo.settings == undefined ){srcjo.settings = new Array();}   
		var len = srcjo.settings.push( setting );
		srcjo.settings[len - 1].index = len - 1;
		return len - 1;
	},
	
	//濡傛灉validator瀵硅薄瀵瑰簲镄别lement瀵硅薄镄剉alidator灞炴€ц拷锷犺杩涜镄勬牎楠屻€?
	getInitConfig : function( validatorGroup )
	{
		if(jQuery_formValidator_initConfig!=null)
		{
		    for(i=0;i<jQuery_formValidator_initConfig.length;i++)
		    {
		        if(validatorGroup==jQuery_formValidator_initConfig[i].validatorGroup)
				{
					return jQuery_formValidator_initConfig[i];
				}
		    }
		}
		return null;
	},
	
	//瑙﹀彂姣忎釜鎺т欢涓婄殑鍚勭镙￠獙
	triggerValidate : function(returnObj)
	{
		switch(returnObj.setting.validateType)
		{
			case "InputValidator":
				$.formValidator.InputValid(returnObj);
				break;
			case "CompareValidator":
				$.formValidator.CompareValid(returnObj);
				break;
			case "AjaxValidator":
				$.formValidator.AjaxValid(returnObj);
				break;
			case "RegexValidator":
				$.formValidator.RegexValid(returnObj);
				break;
			case "FunctionValidator":
				$.formValidator.FunctionValid(returnObj);
				break;
		}
	},
	
	//璁剧疆鏄剧ず淇℃伅
	SetTipState : function(tipid,showclass,showmsg)
	{
	    var tip = $("#"+tipid);
	    tip.removeClass();
	    tip.addClass( showclass );
	    tip.html( showmsg );
	},
	
	//璁剧疆阌栾镄勬樉绀轰俊鎭?
	SetFailState : function(tipid,showmsg)
	{
	    var tip = $("#"+tipid);
	    tip.removeClass();
	    tip.addClass( "onError" );
	    tip.html( showmsg );
	},

	//镙规嵁鍗曚釜瀵硅薄,姝ｇ‘:姝ｇ‘鎻愮ず,阌栾:阌栾鎻愮ず
	ShowMessage : function(returnObj)
	{
	    var id = returnObj.id;
		var isValid = returnObj.isValid;
		var setting = returnObj.setting;//姝ｇ‘:setting[0],阌栾:瀵瑰簲镄剆etting[i]
		var showmsg = "";
		var showclass = "";
		var settings = $("#"+id).get(0).settings;
		if (!isValid)
		{		
			if(setting.validateType=="AjaxValidator")
			{
				if(setting.lastValid=="")
				{
				    showclass = "onLoad";
				    showmsg = setting.onwait;
				}
				else
				{
				    showclass = "onError";
				    showmsg = setting.onerror;
				}
			}
			else
			{
				showmsg = (returnObj.errormsg==""? setting.onerror : returnObj.errormsg);
				showclass = "onError";
			}
			if($.formValidator.getInitConfig(settings[0].validatorGroup).alertMessage)		
			{
				var elem = $("#"+id).get(0);
				if(elem.validoldvalue!=$(elem).val()) alert(showmsg);   
			}
			else
			{
				$.formValidator.SetTipState(settings[0].tipid,showclass,showmsg);
			}
		}
		else
		{		
			//楠岃瘉鎴愬姛鍚?濡傛灉娌℃湁璁剧疆鎴愬姛鎻愮ず淇℃伅,鍒欑粰鍑洪粯璁ゆ彁绀?鍚﹀垯缁椤嚭镊畾涔夋彁绀?鍏佽涓虹┖,链间负绌虹殑鎻愮ず
			if(!$.formValidator.getInitConfig(setting.validatorGroup).alertMessage)
			{
				var showmsg = "";
				if ( $.formValidator.IsEmpty(id)){ 
					showmsg = setting.onempty;
				}else{
					showmsg = setting.oncorrect;
				}
			    $.formValidator.SetTipState(setting.tipid,"onSuccess",showmsg);
			}
		}
	},
    
	//銮峰彇鎸囧畾瀛楃涓茬殑闀垮害
    GetLength : function(id)
    {
        var srcjo = $("#"+id);
        sType = srcjo.get(0).type;
        var len = 0;
        switch(sType)
		{
			case "text":
			case "hidden":
			case "password":
			case "textarea":
			case "file":
		        var val = srcjo.val();
				for (var i = 0; i < val.length; i++) 
                {
			        if (val.charCodeAt(i) >= 0x4e00 && val.charCodeAt(i) <= 0x9fa5){ 
				        len += 2;
			        }else {
				        len++;
					}
		        }
		        break;
			case "checkbox":
			case "radio": 
				len = $("input[@type='"+sType+"'][@name='"+srcjo.attr("name")+"'][@checked]").length;
				break;
		    case "select-one":
		        len = srcjo.get(0).options ? srcjo.get(0).options.selectedIndex : -1;
				break;
			case "select-more":
				break;
	    }
		return len;
    },
    
	//缁揿悎empty杩欎釜灞炴€э紝鍒ゆ柇浠呬粎鏄惁涓虹┖镄勬牎楠屾儏鍐点€?
    IsEmpty : function(id)
    {
        if($("#"+id).get(0).settings[0].empty && $.formValidator.GetLength(id)==0){
            return true;
        }else{
            return false;
		}
    },
    
	//瀵瑰璋幂敤锛氩垽鏂崟涓〃鍗曞厓绱犳槸鍚﹂獙璇侀€氲绷锛屼笉甯﹀洖璋冨嚱鏁?
    IsOneValid : function(id)
    {
	    return OneIsValid(id,1).isValid;
    },
    
	//楠岃瘉鍗曚釜鏄惁楠岃瘉阃氲绷,姝ｇ‘杩斿洖settings[0],阌栾杩斿洖瀵瑰簲镄剆ettings[i]
	OneIsValid : function (id,index)
	{
		var returnObj = new Object();
		returnObj.id = id;
		returnObj.ajax = -1;
		returnObj.errormsg = "";       //镊畾涔夐敊璇俊鎭?
		var elem = $("#"+id).get(0);
	    var settings = elem.settings;
	    var settingslen = settings.length;
		if($.formValidator.IsEmpty(id))
	    {
			returnObj.setting = settings[0];
	        returnObj.isValid = true;
	    }
	    else
	    {
		    for ( var i = index ; i < settingslen ; i ++ )
		    {   
			    returnObj.setting = settings[i];
			    if(settings[i].validateType!="AjaxValidator") {
			        $.formValidator.triggerValidate(returnObj);
			    }else{
			        returnObj.ajax = i;
				}
			    if(!settings[i].isValid) {
			        returnObj.isValid = false;
			        returnObj.setting = settings[i];
			        break;
			    }else{
			        returnObj.isValid = true;
					returnObj.setting = settings[0];
			        if(settings[i].validateType=="AjaxValidator") break;
			    }
		    }
		}
		//鎴愬姛鍚庣殑锲炶皟鍑芥暟
		if(returnObj.isValid)
		{
			var lb_ret = returnObj.setting.onvalid($("#"+id).get(0),$("#"+id).val());
			if(lb_ret != undefined) 
			{
				if(typeof lb_ret == "string"){
					returnObj.errormsg = lb_ret;		//镊畾涔夐敊璇?
					returnObj.isValid = false;
				}else{
					settings[settings.length - 1].isValid = lb_ret;
					returnObj.isValid = lb_ret;
				}
			}
			
		}
		return returnObj;
	},

	//楠岃瘉镓€链夐渶瑕侀獙璇佺殑瀵硅薄锛屽苟杩斿洖鏄惁楠岃瘉鎴愬姛銆?
	PageIsValid : function (validatorGroup)
	{
	    if(validatorGroup == null || validatorGroup == undefined) validatorGroup = "1";
		var isValid = true;
		var thefirstid = "";
		var returnObj,setting;
		var error_tip = "^"; 	//涓轰简瑙ｅ喅浣跨敤鍚屼釜TIP鎻愮ず闂:鍚庨溃镄勬垚锷熸垨澶辫触閮戒笉瑕嗙洊鍓嶉溃镄勫け璐?
		$("form").each(function(i,form1)
		{
			for(i=0;i<form1.elements.length;i++)  
			{
				elem = form1.elements[i];
				if ( elem.settings!=undefined && elem.settings!=null )
				{ 
					if(elem.settings[0].validatorGroup==validatorGroup)
					{
						if($.formValidator.getInitConfig(validatorGroup).alertMessage) 
						{
							if(isValid)		//濡傛灉鏄脊鍑虹獥鍙ｇ殑,鍙戠幇涓€涓敊璇氨椹笂锅沧,骞舵彁绀?
							{
								returnObj = $.formValidator.OneIsValid(elem.id,1);	
								if (!returnObj.isValid) {
									$.formValidator.ShowMessage(returnObj);
									isValid = false;
									if(thefirstid==""){
									    thefirstid = returnObj.id;
									    setting = returnObj.setting;
									}
								}
							}
						}
						else
						{
							returnObj = $.formValidator.OneIsValid(elem.id,1);	
							if (!returnObj.isValid) {
								isValid = false;
								if (thefirstid == "")
								{
								    thefirstid = returnObj.id;
								    setting = returnObj.setting;
								}
								if (error_tip.indexOf("^" + elem.settings[0].tipid + "^") == -1) {
									error_tip = error_tip + elem.settings[0].tipid + "^";
									$.formValidator.ShowMessage(returnObj);
								}
							}
							else
							{
								if (error_tip.indexOf("^" + elem.settings[0].tipid + "^") == -1) {
									$.formValidator.ShowMessage(returnObj);
								}
							}
							
						}
					}
				}
			};
		});
		//鎴愬姛鎴栧け璐ュ悗锛岃繘琛屽洖璋冨嚱鏁扮殑澶勭悊锛屼互鍙婃垚锷熷悗镄勭伆鎺夋彁浜ゆ寜阍殑锷熻兘
		if(isValid)
		{
            isValid = $.formValidator.getInitConfig(validatorGroup).onSuccess();
			if($.formValidator.getInitConfig(validatorGroup).submitOnce){$("input[@type='submit']").attr("disabled",true);}
		}
		else
		{
			$.formValidator.getInitConfig(validatorGroup).onError(setting.onerror,$("#"+thefirstid));
			if(thefirstid!=""){$("#"+thefirstid).focus();}
		}
		return isValid;
	},

	//ajax镙￠獙
	AjaxValid : function(returnObj)
	{
		var id = returnObj.id;
	    var srcjo = $("#"+id);
		var setting = srcjo.get(0).settings[returnObj.ajax];
		var ls_url = setting.url;
	    if (srcjo.size() == 0 && srcjo.get(0).settings[0].empty) {
			returnObj.setting = $("#"+id).get(0).settings[0];
			returnObj.isValid = true;
			$.formValidator.ShowMessage(returnObj);
			setting.isValid = true;
			return;
		}
		if(setting.addidvalue)
		{
			var parm = id+"="+escape(srcjo.val());
			ls_url = ls_url + ((ls_url).indexOf("?")>0?("&"+ parm) : ("?"+parm));
		}
		$.ajax(
		{	
			mode : "abort",
			type : setting.type, 
			url : ls_url, 
			data : setting.data, 
			async : setting.async, 
			dataType : setting.datatype, 
			success : function(data){
			    setting0 = srcjo.get(0).settings[0];
			    if(setting.success(data))
			    {
			        $.formValidator.SetTipState(setting0.tipid,"onSuccess",setting0.oncorrect);
			        setting.isValid = true;
			    }
			    else
			    {
			        $.formValidator.SetTipState(setting0.tipid,"onError",setting.onerror);
			        setting.isValid = false;
			    }
			},
			complete : function(){
				if(setting.buttons && setting.buttons.length > 0) setting.buttons.attr({"disabled":false});
				setting.complete;
			}, 
			beforeSend : function(){
				//鍐嶆湇锷″櫒娌℃湁杩斿洖鏁版嵁涔嫔墠锛屽厛锲炶皟鎻愪氦鎸夐挳
				if(setting.buttons && setting.buttons.length > 0) setting.buttons.attr({"disabled":true});
				var isvalid = setting.beforesend();
				if(isvalid) setting.isValid = false;		//濡傛灉鍓嶉溃ajax璇锋眰鎴愬姛浜嗭紝鍐嶆璇锋眰涔嫔墠鍏埚綋浣滈敊璇鐞?
				setting.lastValid = "-1";
				return setting.beforesend;
			}, 
			error : function(){
				setting0 = srcjo.get(0).settings[0];
			    $.formValidator.SetTipState(setting0.tipid,"onError",setting.onerror);
			    setting.isValid = false;
				setting.error();
			},
			processData : setting.processdata 
		});
	},

	//瀵规鍒栾〃杈惧纺杩涜镙￠獙锛堢洰鍓嶅彧阍埚input鍜宼extarea锛?
	RegexValid : function(returnObj)
	{
		var id = returnObj.id;
		var setting = returnObj.setting;
		var srcTag = $("#"+id).get(0).tagName;
		var elem = $("#"+id).get(0);
		//濡傛灉链夎緭鍏ユ鍒栾〃杈惧纺锛屽氨杩涜琛ㄨ揪寮忔牎楠?
		if(elem.settings[0].empty && elem.value==""){
			setting.isValid = true;
		}
		else 
		{
			var regexpress = setting.regexp;
			if(setting.datatype=="enum"){regexpress = eval("regexEnum."+regexpress);}
			if(regexpress==undefined || regexpress==""){
				setting.isValid = false;
				return;
			}
			var exp = new RegExp(regexpress, setting.param);
			if (exp.test($("#"+id).val())){
				setting.isValid = true;
			}else {
				setting.isValid = false;
			}
		}
	},
	
	//鍑芥暟镙￠獙銆傝繑锲潇rue/false琛ㄧず镙￠獙鏄惁鎴愬姛;杩斿洖瀛楃涓茶〃绀洪敊璇俊鎭紝镙￠獙澶辫触;濡傛灉娌℃湁杩斿洖链艰〃绀哄鐞嗗嚱鏁帮紝镙￠獙鎴愬姛
	FunctionValid : function(returnObj)
	{
		var id = returnObj.id;
		var setting = returnObj.setting;
	    var srcjo = $("#"+id);
		var lb_ret = setting.fun(srcjo.val(),srcjo.get(0));
		if(lb_ret != undefined) 
		{
			if(typeof lb_ret == "string"){
				setting.isValid = false;
				returnObj.errormsg = lb_ret;
			}else{
				setting.isValid = lb_ret;
			}
		}
	},
	
	//瀵筰nput鍜宻elect绫诲瀷鎺т欢杩涜镙￠獙
	InputValid : function(returnObj)
	{
		var id = returnObj.id;
		var setting = returnObj.setting;
		var srcjo = $("#"+id);
		var elem = srcjo.get(0);
		var val = srcjo.val();
		var sType = elem.type;
		var len = $.formValidator.GetLength(id);
		switch(sType)
		{
			case "text":
			case "hidden":
			case "password":
			case "textarea":
			case "file":
			case "checkbox":
			case "select-one":
			case "radio":
				if(sType=="select-one"){setting.type = "size";}
				if (setting.type == "size") {		//銮峰缑杈揿叆镄勫瓧绗﹂昵搴︼紝骞惰繘琛屾牎楠?
					if (len < setting.min || len > setting.max) {
						setting.isValid = false;
					}
					else {
						setting.isValid = true;
					}
				}
				else{
					stype = (typeof setting.min);
					if(stype =="number")
					{
						if(!isNaN(val))
						{
							nval = parseFloat(val);
							if(nval>=setting.min && nval<= setting.max){
								setting.isValid = true;
							}else{
								setting.isValid = false;
							}
						}
						else
							setting.isValid = false;
					}
					if(stype =="string"){
						if(val>=setting.min && val<= setting.max){
							setting.isValid = true;
						}else{
							setting.isValid = false;
						}
					}
				}
				break;
		    case "select-more":
                break;
		}
	},
	
	CompareValid : function(returnObj)
	{
		var id = returnObj.id;
		var setting = returnObj.setting;
		var srcjo = $("#"+id);
	    var desjo = $("#"+setting.desID );
	    setting.isValid = false;
		curvalue = srcjo.val();
		ls_data = desjo.val();
		if(setting.datatype=="number")
        {
            if(!isNaN(curvalue) && !isNaN(ls_data))
			{
				curvalue = parseFloat(curvalue);
                ls_data = parseFloat(ls_data);
			}
			else
			{
			    return;
			}
        }
		
	    switch(setting.operateor)
	    {
	        case "=":
	            if(curvalue == ls_data){setting.isValid = true;}
	            break;
	        case "!=":
	            if(curvalue != ls_data){setting.isValid = true;}
	            break;
	        case ">":
	            if(curvalue > ls_data){setting.isValid = true;}
	            break;
	        case ">=":
	            if(curvalue >= ls_data){setting.isValid = true;}
	            break;
	        case "<": 
	            if(curvalue < ls_data){setting.isValid = true;}
	            break;
	        case "<=":
	            if(curvalue <= ls_data){setting.isValid = true;}
	            break;
	        case "oneok":
	            if($.formValidator.IsEmpty(id) || $.formValidator.IsEmpty(IsEmpty.desID) ){
	                setting.isValid = false;
				}else{
	                setting.isValid = true;
				}
	    }
	}
};

//姣忎釜镙￠獙鎺т欢蹇呴』鍒濆鍖栫殑
$.fn.formValidator = function( msgOptions) 
{
	var setting = 
	{
		validatorGroup : "1",
		empty :false,
		submitonce : false,
		automodify : false,
		entermovetonext : true,
		onshow :"璇疯緭鍏ュ唴瀹?,
		onfocus: "璇疯緭鍏ュ唴瀹?,
		oncorrect: "杈揿叆姝ｇ‘",
		onempty: "杈揿叆鍐呭涓虹┖",
		onvalid : function(){return true},
		onfocusevent : function(){},
		onblurevent : function(){},
		tipid : this.get(0).id+"Tip",
		defaultvalue : null,
		validateType : "InitValidator"
	};
	msgOptions = msgOptions || {};
	$.extend(setting, msgOptions);
	return this.each(function()
	{
		var triggerID = this.id;
		var tip = $( "#"+setting.tipid );
		$.formValidator.appendValid(triggerID,setting);
		//鍒濆鍖栨樉绀轰俊鎭?
		if(!$.formValidator.getInitConfig(setting.validatorGroup).alertMessage){
			$.formValidator.SetTipState(setting.tipid,"onShow",setting.onshow);
		}
		var srcTag = this.tagName;
		var defaultValue = setting.defaultvalue;
		if (srcTag == "INPUT" || srcTag=="TEXTAREA")
		{
			var stype = this.type;
			var joeach = $(this);
			if (stype == "checkbox" || stype == "radio") {
				joeach = $("input[@name=" + this.name + "]");
				if(defaultValue)
				{
					checkobj = $("input[@name=" + this.name + "][@value='"+defaultValue+"']");
					if(checkobj.length==1) checkobj.attr("checked","true");
				}
			}
			else
			{
			    if(defaultValue) joeach.val(setting.defaultvalue);
			}
			//娉ㄥ唽銮峰缑铹︾偣镄勪簨浠躲€傛敼鍙樻彁绀哄璞＄殑鏂囧瓧鍜屾牱寮忥紝淇濆瓨铡熷€?
			joeach.focus(function()
			{	
				var settings = joeach.get(0).settings;
				if(!$.formValidator.getInitConfig(settings[0].validatorGroup).alertMessage){
				    $.formValidator.SetTipState(settings[0].tipid,"onFocus",settings[0].onfocus);
				}
				if (stype == "password" || stype == "text" || stype == "textarea" || stype == "file") {
					this.validoldvalue = $(this).val();
				}
				settings[0].onfocusevent(joeach.get(0));
			});
			//娉ㄥ唽澶卞幓铹︾偣镄勪簨浠躲€傝繘琛屾牎楠岋紝鏀瑰彉鎻愮ず瀵硅薄镄勬枃瀛楀拰镙峰纺锛涘嚭阌椤氨鎻愮ず澶勭悊
			joeach.blur(function()
			{   
				var elem = joeach.get(0);
				var thefirstsettings = elem.settings;
				var settingslen = thefirstsettings.length;
				var returnObj = $.formValidator.OneIsValid(triggerID,1);
				if(returnObj.ajax >= 0 && elem.validoldvalue!=$(elem).val()) 
				{
			        $.formValidator.SetTipState(thefirstsettings[0].tipid,"onLoad",thefirstsettings[returnObj.ajax].onwait);
				    $.formValidator.AjaxValid(returnObj);
				}
				else
				{
				    $.formValidator.ShowMessage(returnObj);
					if(!returnObj.isValid)
					{
						//镊姩淇阌栾
						var auto = thefirstsettings[0].automodify && (elem.type=="text" || elem.type=="textarea" || elem.type=="file");
						if(auto && !$.formValidator.getInitConfig(thefirstsettings[0].validatorGroup).alertMessage)
						{
							alert(returnObj.setting.onerror);
							$.formValidator.SetTipState(thefirstsettings[0].tipid,"onShow",setting.onshow);
						}
					}
				}
				thefirstsettings[0].onblurevent(joeach.get(0));
			});
		} 
		else if (srcTag == "SELECT")
		{
		    srcjo = $(this);
		    var settings = this.settings;
		    if (defaultValue)
		    {			 
			    $.each( this.options ,function(){	
				    if ( this.value==defaultValue) this.selected = true;		  
			    });				  
		    }

			srcjo.focus(function()
			{	
				if(!$.formValidator.getInitConfig(setting.validatorGroup).alertMessage){
				    $.formValidator.SetTipState(settings[0].tipid,"onFocus",settings[0].onfocus);
				}
			});
			
			srcjo.bind( "change" , function()
			{
				var returnObj = $.formValidator.OneIsValid(triggerID,1);	 
				if ( returnObj.ajax >= 0 && this.validoldvalue!=$(this).val()){
				    $.formValidator.AjaxValid(triggerID, returnObj.setting);
				}else{
					$.formValidator.ShowMessage(returnObj);    
				}
			});
		}
	});

}; 

$.fn.InputValidator = function(controlOptions)
{
	var settings = 
	{
		isValid : false,
		min : 0,
		max : 99999999999999,
		forceValid : false,
		type : "size",
		defaultValue:null,
		onerror:"杈揿叆阌栾",
		validateType:"InputValidator"
	};
	controlOptions = controlOptions || {};
	$.extend(settings, controlOptions);
	return this.each(function(){
		$.formValidator.appendValid(this.id,settings);
	});
};

$.fn.SelectValidator = function(controlOptions)
{
	var settings = 
	{
		isValid : false,
		onerror:"蹇呴』阃夋嫨",
		defaultValue:null,
		validateType:"SelectValidator"
	};
	controlOptions = controlOptions || {};
	$.extend(settings, controlOptions);
	return this.each(function(){
		$.formValidator.appendValid(this.id,settings);
	});
};

$.fn.CompareValidator = function(controlOptions)
{
	var settings = 
	{
		isValid : false,
		desID : "",
		operateor :"=",
		onerror:"杈揿叆阌栾",
		validateType:"CompareValidator"
	};
	controlOptions = controlOptions || {};
	$.extend(settings, controlOptions);
	return this.each(function(){
		var li_index = $.formValidator.appendValid(this.id,settings);
		/*if(li_index==-1) return;
		var elem = this;
		$("#"+settings.desID).blur(function(){
			var returnObj = $.formValidator.OneIsValid(elem.id,1);
			if (!returnObj.isValid && returnObj.setting.index == li_index) {
				var returnObj = $.formValidator.OneIsValid(elem.id, li_index);
			}
			if ( returnObj.ajax >= 0 && this.validoldvalue!=$(this).val()) {
			    $.formValidator.AjaxValid(triggerID, returnObj.setting);
			}
			else{
				$.formValidator.ShowMessage(returnObj);
			}
		});*/
	});
};

$.fn.RegexValidator = function(controlOptions)
{
	var settings = 
	{
		isValid : false,
		regexp : "",
		param : "i",
		datatype : "string",
		onerror:"杈揿叆镄勬牸寮忎笉姝ｇ‘",
		validateType:"RegexValidator"
	};
	controlOptions = controlOptions || {};
	$.extend(settings, controlOptions);
	return this.each(function(){
		$.formValidator.appendValid(this.id,settings);
	});
};

$.fn.FunctionValidator = function(controlOptions)
{
	var settings = 
	{
		isValid : true,
		onerror:"浣犺緭鍏ョ殑鏁版嵁涓嶆纭紝璇风‘璁?,
		fun : function(){this.isValid = true;},
		validateType:"FunctionValidator"
	};
	controlOptions = controlOptions || {};
	$.extend(settings, controlOptions);
	return this.each(function(){
		$.formValidator.appendValid(this.id,settings);
	});
};

$.fn.AjaxValidator = function(controlOptions)
{
	var settings = 
	{
		isValid : false,
		lastValid : "",
		type : "GET",
		url : "",
		addidvalue : true,
		datatype : "html",
		data : "",
		async : true,
		beforesend : function(){return true;},
		success : function(){return true;},
		complete : function(){},
		processdata : false,
		error : function(){},
		buttons : null,
		onerror:"链嶅姟鍣ㄦ牎楠屾病链夐€氲绷",
		onwait:"姝ｅ湪绛夊緟链嶅姟鍣ㄨ繑锲炴暟鎹?,
		validateType:"AjaxValidator"
	};
	controlOptions = controlOptions || {};
	$.extend(settings, controlOptions);
	return this.each(function()
	{
		$.formValidator.appendValid(this.id,settings);
	});
};

$.fn.DefaultPassed = function()
{
	return this.each(function()
	{
		var settings = this.settings;
		for ( var i = 1 ; i < settings.length ; i ++ )
		{   
			settings[i].isValid = true;
			$.formValidator.SetTipState(settings[0].tipid,"onSuccess",settings[0].oncorrect);
		}
	});
};

})(jQuery);